package com.example.file_management.pojo.user;

import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.datatype.jsr310.deser.LocalDateTimeDeserializer;
import com.fasterxml.jackson.datatype.jsr310.ser.LocalDateTimeSerializer;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.AllArgsConstructor;

import java.time.LocalDateTime;

@Data
@NoArgsConstructor
@AllArgsConstructor
@JsonSerialize(using = LocalDateTimeSerializer.class)
@JsonDeserialize(using = LocalDateTimeDeserializer.class)
public class Role {

    @JsonProperty
    private Long roleId;

    private RoleType roleName;

    private LocalDateTime createdAt;

    private LocalDateTime deletedAt;

    public static enum RoleType {
        SUPER_ADMIN("Super Admin"),
        ADMIN("Admin"),
        DOCUMENT_MANAGER("Document Manager"),
        TASK_MANAGER("Task Manager"),
        REVIEWER("Reviewer"),
        USER("User"),
        GUEST("Guest");

        private final String displayName;

        RoleType(String displayName) {
            this.displayName = displayName;
        }

        public String getDisplayName() {
            return displayName;
        }

        // 静态方法，用于从字符串转换为RoleType枚举实例
        public static RoleType fromString(String value) {
            for (RoleType roleType : values()) {
                if (roleType.displayName.equalsIgnoreCase(value)) {
                    return roleType;
                }
            }
            return null; // 如果找不到匹配的枚举值，则返回null
        }
    }
}